package com.credit.jumu.calculator.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.credit.jumu.calculator.R;
import com.credit.jumu.calculator.bean.OtherResultInfo;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by Administrator on 2017/10/18/018.
 */

public class OtherResultListAdapter extends BaseAdapter {
	private Context context;
	private List<OtherResultInfo> mlistInfo = new ArrayList<OtherResultInfo>();

	public OtherResultListAdapter(List<OtherResultInfo> mlistInfo, Context context) {
		this.context = context;
		this.mlistInfo = mlistInfo;

	}

	@Override
	public int getCount() {
		return mlistInfo.size();
	}

	@Override
	public Object getItem(int position) {
		return mlistInfo.get(position);
	}

	@Override
	public long getItemId(int position) {
		return position;
	}

	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		ViewHolder viewHolder = null;
		if (null == viewHolder) {
			LayoutInflater inflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
			convertView = inflater.inflate(R.layout.item_other_result, null);
			viewHolder = new ViewHolder();

			viewHolder.phase = (TextView) convertView.findViewById(R.id.phase);
			viewHolder.monthMoney = (TextView) convertView.findViewById(R.id.monthMoney);
			viewHolder.principal = convertView.findViewById(R.id.principal);
			viewHolder.interest = convertView.findViewById(R.id.interest);
			convertView.setTag(viewHolder);
		} else {
			viewHolder = (ViewHolder) convertView.getTag();
		}
		viewHolder.phase.setText(mlistInfo.get(position).getPhase());
		viewHolder.monthMoney.setText(mlistInfo.get(position).getMonthMoney());
		viewHolder.principal.setText(mlistInfo.get(position).getPrincipal());
		viewHolder.interest.setText(mlistInfo.get(position).getInterest());

		return convertView;
	}

	private class ViewHolder {
		private TextView phase;
		private TextView monthMoney;
		private TextView principal;
		private TextView interest;
	}
}

